<?php
/**
 * Author Yulin
 * Email  dwzhanglong@126.com
 * Date   2017-7-21
 * Func   用户资料
 */
defined('IN_YuLin') || exit('NO PERMIT!');

UserLogin(U($m.'/'.$c.'/'.$a));

$table = Table('user_info');

//	用户信息
$data = $db->getrow('SELECT * FROM '.$table.' WHERE uid = '.$_uid);
$info = $db->getrow('select * from '.Table('user').' where id ='.$_uid);
if(!$data)
{
	$db->exec('INSERT INTO '.$table.'(uid) VALUES ('.$_uid.')');
}

if(IS_POST)
{
	$nickname 	= NoBadStr($_POST['nickname']);
	$truename 	= NoBadStr($_POST['truename']);
	$email	 	= NoBadStr($_POST['email']);
	$mobile 	= NoBadStr($_POST['mobile']);
	$qq 		= NoBadStr($_POST['qq']);
	$wechat		= NoBadStr($_POST['wechat']);
	
	$ins = [];
	
	if(!$data['nickname'])
	{
		!$nickname && AjaxReturn(1,'昵称不能为空');
		
		//$tmp = $db->getrow('SELECT 1 FROM '.$table.' WHERE nickname = \''.$nickname.'\'');
		//$tmp && AjaxReturn(1,'该昵称已经被使用了');
		
		$ins['nickname'] = $nickname;
	}
	
	if(!$data['truename'])
	{
		!$truename && AjaxReturn(1,'姓名不能为空');
		
		//$tmp = $db->getrow('SELECT 1 FROM '.$table.' WHERE nickname = \''.$nickname.'\'');
		//$tmp && AjaxReturn(1,'该昵称已经被注册了');
		
		$ins['truename'] = $truename;
	}
	
	if(!$data['email'])
	{
		!CheckEmail($email) && AjaxReturn(1,'邮箱填写有误');
		
		$tmp = $db->getrow('SELECT 1 FROM '.$table.' WHERE email = \''.$email.'\'');
		$tmp && AjaxReturn(1,'该邮箱已经被使用了');
		
		$ins['email'] = $email;
	}
	
	if(!$data['mobile'])
	{
		!$mobile && AjaxReturn(1,'电话不能为空');
		
		//$tmp = $db->getrow('SELECT 1 FROM '.$table.' WHERE mobile = \''.$mobile.'\'');
		//$tmp && AjaxReturn(1,'该电话已经被注册了');
		
		$ins['mobile'] = $mobile;
	}
	
	if(!$data['qq'])
	{
		!$qq && AjaxReturn(1,'QQ不能为空');
		
		$ins['qq'] = $qq;
	}
	
	if(!$data['wechat'])
	{
		//!$wechat && AjaxReturn(1,'微信不能为空');
		
		$ins['wechat'] = $wechat;
	}
	
	$ins && $db->update('user_info',$ins,'uid = '.$_uid);
	
	AjaxReturn(0,'修改资料成功！');
}

if($a == 'api')	//	会员信息接口
{
	$data = [];
	$data['AccountName']	=	$_user['username'];
	$data['UserName']		=	$_user['username'];
	$data['GradeName']		=	'会员';
	$data['Handicap']		=	1;
	$data['CreditBalance']	=	$_user['money'];
	$data['CreditTitle']	=	'系统余额';
	
	echo json_encode($data);	
	exit;
}

$head['title'] = '用户资料';

$tpl->display('member/info');